The parser is a hand-coded recursive descent parser. It includes a sophisticated
error recovery system, which among other things takes indentation into
account when attempting to correct scope errors. In our experience, the
recovery is superior to that of other compilers, and the parser is remarkably
stable in the presence of badly mangled programs. All GNU compilers heretofore
had used LALR(1) parsers generated with Bison (The GNU equivalent of YACC).
The choice of a handwritten parser at this date may seem surprising, but is
amply justified by the following:
- <#2746#>Clarity.<#2746#>
- The parser follows carefully the grammar given in the
Ada9X reference manual. ([#rm-9x##1###]). This has clear pedagogical advantages,
but precludes the use of a table-driven parser, given that the grammar
as given is not LALR(k).
- <#2747#>Error messages.<#2747#>
- The most important reason is the quality of the
error reporting. Even in case of serious structural errors, such as an
interchange of ``<#453#>;<#453#>'' and ``<#454#>is<#454#>'' between specification and body
of a subprogram, GNAT generates a precise and intelligible message. Bottom-up
parsers have serious difficulties with such errors.
- <#2748#>Performance.<#2748#>
- Even though the overall performance of the system is
bounded by the speed of the code generator, it does not hurt that the parser
of GNAT is faster than any table-driven one.